package server;

import pojo.Student;

import java.sql.*;

public class jdbc2 {
    public static void main(String[] args) {
        Student one = getOne(2);
        System.out.println(one);
    }
    public static Student getOne(int id){
        Connection conn = null;
        Statement statement = null;
        ResultSet rs = null;
        Student student = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybattis?serverTimezone=UTC", "root", "root");
            statement = conn.createStatement();
            String sql = "select * from student where id ="+id;
            rs  = statement.executeQuery(sql);
            while (rs.next()){
                student = new Student();
                student.setId(rs.getInt("id"));
                student.setName(rs.getNString("name"));
                student.setTid(rs.getInt("tid"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                statement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return student;
    }
}
